
# path = C:\Users\jason\Desktop
import time
i = 1

temp = '''
-----------------------
    错误：%s
    警告：%s
    调试：%s
    消息：%s
-----------------------
'''
# file_handle = open(file=r"E:\b.txt",mode="r+",encoding="utf-8")

while  True:
    i = i + 1
    time.sleep(0.5)

    file = open(file=r"E:\a.log",mode="r",encoding="utf-8")

    data = file.readlines()

    '''
        da = {
            "W":121,
            "D":50,
            "I":120,
            "E":2
        }
    '''
    dic = {}
    file_handle = open(file=r"E:\b.txt", mode="w", encoding="utf-8")
    for index,line in enumerate(data):
        # print(index ,"-------------",line)
        if  len(line[0].strip()) == 0:
            continue
        else:
            value = line[31]
            if value in dic:  # 计数器之前是否存在过E
                dic[value] =  dic[value] + 1
            else:# 如果之前没有统计过，直接初始化为1
                dic[value] = 1
            if value == "E":
                lis = line.split(":")
                print(lis[0],"".join(lis[1:]))
                # 继续将错误消息日志，导出到E.log文件
                a = lis[0]
                b = "".join(lis[1:])

                file_handle.writelines([a,b,'\n'])
    file_handle.close()
    print(temp % (dic["E"],dic["W"],dic["D"],dic["I"]))
    # print(data)
    file.close()

# file_handle.close()





















